{extend name="public/layer_base" /}
{block name='content'}

<div class="layui-fluid x-admin-sm">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="xadmin.open('添加','{:url('add')}')"><i
                            class="layui-icon"></i>添加</button>
                    <button class="layui-btn layui-btn-danger " id="allDel"><i class="layui-icon"></i>删除</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form" id="adminMenuId" ></table>
                </div>

            </div>
        </div>
    </div>
    <style>
        .layui-table-cell .layui-form-checkbox[lay-skin=primary] {
            top: 6px;
        }
    </style>
 
    <script>
        layui.use(['table', 'layer', "treeTable"], function () {
            var table = layui.table
                , $ = layui.$
                , treeTable = layui.treeTable
                , form = layui.form
                , layer = layui.layer,
                menu = JSON.parse('{$data|raw}'),
                menuData = [];

                for (vo in menu){
                    menu[vo].pid = menu[vo].parent_id
                    menuData.push(menu[vo]);
                }
            var treeTableResult = treeTable.render({
                elem: '#adminMenuId',
                data: menuData,
                icon_key: 'name',
                is_checkbox: true,
                end: function (e) {
                    form.render();
                },
                cols: [
                    {
                        key: 'name',
                        title: '菜单名称',
                        width: '150px',
                     
                    },
                    {
                        key: 'url',
                        title: 'url',
                        width: '180px',
                        align: 'center',
                    },
                    {
                        key: 'icon',
                        title: '图标',
                        width: '180px',
                        align: 'center',
                        template:function(item){
                            return '<i class="fa '+ item.icon+'"></i>';
                        }
                    },
                    {
                        key: 'sort_id',
                        title: '排序',
                        width: '180px',
                        align: 'center',
                    },
                    {
                        key: 'is_show',
                        title: '状态',
                        width: '150px',
                        align: 'center',
                        template: function (item) {
                            return item.is_show ? '显示' : '隐藏';
                            }
                    },
                    {
                        key: 'log_method',
                        title: '日志记录方式',
                        width: '180px',
                        align: 'center',
                        
                    },
                    {
                        title: '操作',
                        align: 'center',
                        template: function (item) {
                            return "<button  onclick=xadmin.open('修改','"+"/admin/admin_menu/edit.html?id=" + item.id+ "')  class='layui-btn  layui-bg-blue layui-btn-xs' title='修改'  > <i class='layui-icon layui-icon-edit'></i> 修改  </button> <button class='layui-btn layui-btn-danger AjaxButton layui-btn-xs' data-toggle='tooltip' title='删除' data-id='"  + item.id+ "' data-confirm-title='删除确认'  data-confirm-content='您确定要删除ID为 <span class=text-red>" + item.id+ "</span> 的数据吗' data-url='/admin/admin_menu/del.html'>  <i  class='layui-icon'></i>删除 </button>";
                        }
                    }
                ]
            });

            $('#allDel').click(function () {
                let data = treeTable.checked(treeTableResult).join(',');
                dataData = {
                    "id": data
                };
                layer.confirm('确认要删除吗', {
                    title: '删除确认',
                    closeBtn: 1,
                    icon: 3
                }, function () {
                    ajaxRequest({
                        host: "{:url('del')}",
                        method: "post",
                        data: dataData,
                        success: function (result) {
                            layer.msg(result.msg, {
                                icon: result.code ? 1 : 2,
                                time: 1000,
                                scrollbar: false,
                            }, function () {
                                goUrl(2);

                            });
                        }
                    });
                }
                )
            })

        });
    </script>
    {/block}